from rest_framework import serializers
from rest_framework.serializers import ModelSerializer

from cart.models import CartModel
from course import courseser
from course.models import CourseModel


# class CourserSeria(ModelSerializer):
#     class Meta:
#         model = CourseModel
#         fields = ['cname','price','cover','discount']
#
# class CartSerializer(ModelSerializer):
#     course = courseser.CourseSerializer()
#     class Meta:
#         model = CartModel
#         fields = '__all__'
#
#
# class CartSer(ModelSerializer):
#     class Meta:
#         model = CartModel
#         fields = '__all__'

class CartSerializer(ModelSerializer):
    courselist = serializers.SerializerMethodField(read_only=True)
    def get_courselist(self,obj):
        return {"level":obj.course.level,"id":obj.course.id,"cname":obj.course.cname,"price":obj.course.price,"cover":str(obj.course.cover),"discount":obj.course.discount}
    class Meta:
        model = CartModel
        fields = '__all__'